<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateBotTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $table = $this->table('bots', ['comment'=>'机器人','engine'=>'InnoDB']);
        $table->addColumn('name', 'string', ['limit'=>255, 'default'=>'', 'comment'=>'机器人名','null'=> false])
            ->addColumn('token','string',['limit'=>255, 'default'=>'', 'comment'=>'机器人token','null'=> false])
            ->addColumn('avatar', 'string', ['limit'=> 255, 'default'=>'', 'comment'=>'机器人头像', 'null'=> false])
            ->addColumn('bot_id', 'integer', ['signed'=> true, 'default'=> 0, 'comment'=>'所属机器人', 'null'=> false])
            ->addColumn('backup_user_id', 'string', ['limit'=>255, 'default'=>'', 'comment'=>'备份人的chat_id或username', 'null'=>false])
            ->addColumn('enable', 'boolean', ['comment'=>'是否启用','default'=> false])
            ->addColumn('created_at', 'timestamp', ['default'=>'CURRENT_TIMESTAMP', 'null'=>false, 'comment'=>'创建时间'])
            ->addColumn('updated_at','timestamp', ['default'=> null, 'null'=>true, 'comment'=>'修改时间'])
            ->addColumn('deleted_at','datetime', ['default'=> null, 'null'=>true, 'comment'=>'删除时间'])
            ->create();
        
        $bot_command_table = $this->table('bot_command', ['comment'=>'机器人命令','engine'=>'InnoDB']);
        $bot_command_table->addColumn('alias', 'string', ['limit'=>255, 'default'=> '', 'null'=> false, 'comment'=>'命令别名'])
            ->addColumn('class', 'string', ['limit'=>255, 'default'=>'', 'null'=>false, 'comment'=>'命令类名'])
            ->addColumn('bot_id', 'integer', ['signed'=> true, 'default'=> 0, 'comment'=>'所属机器人', 'null'=> false])
            ->create();
    }
}
